xeenfandomcom-20200213-history
Event Scripting
Events are scripted interactions that can be placed at any position on any map. They can take a variety of inputs, with access to input from the player in the form of getting them to enter a word or phrase, choose from a number of pre-set options, or selecting a character. Events can modify a wide variety of in-game variables: character stats, health, conditions, party gold, gems, awards, and so forth. They can also modify the map by adding monsters, changing tiles, adding objects, removing objects, and removing events, as well as providing output to the player in the form of NPC dialogs and output windows full of text, playing sound effects or CD audio, etc. The events for a given map are stored in a file named MAZExxxx.EVT, where xxxx is a decimal representation of the map number. Like all other map files used by the Xeen engine, the first zero is replaced by an 'X' if the map number is greater than 99: MAZE0024.EVT for map number 24, and MAZEX128.EVT for map number 128. Each individual event is stored as a set of lines, each of which contains an instruction for the engine to execute. The lines are numbered, so that it is possible to jump between lines using the equivalent of a GOTO command. The event file itself consists of these lines all stored one after the other. Each line consists of: * Length byte - the next n bytes make up this line * - the X-offset of this event * - the Y-offset of this event * - the directions this event can be triggered from * Line number (byte) - the relative number of this line in the current event * Opcode byte - the command to execute * Optional arguments - any number of bytes The X, Y, and facing bytes combine to indicate the tile the party must be standing on, and the direction they must be facing to trigger the event. A direction value of 4 means that the event can be triggered if the party is facing any direction. Event Example The raw data from the Vertigo event file has been broken down to show the line structure: 08 10 08 04 00 09 14 F5 02 08 10 08 04 01 08 09 00 05 06 10 08 04 02 01 1C 08 10 08 04 03 09 2C 01 04 05 10 08 04 04 12 07 10 08 04 05 20 00 28 0E 10 08 04 06 14 64 0A 00 00 00 00 00 00 00 09 10 08 04 07 0C 00 00 14 F5 The first byte of each line shows the length of the line data (the number of following bytes. The next three bytes are the X, Y, and facing bytes: this event is located at X=16, Y=8, and can be triggered from any direction. The next byte is the line number. This is always incremented by one in every original Xeen game event examined. There is always at least one more byte: the opcode for the command the engine should perform, which may have data bytes. In the above example, all the lines except line 4 (opcode 0x12) have at least one data byte. 00: If 14 F5 02 01: If 09 00 05 02: Display0x01 1C 03: If 2C 01 04 04: Exit 05: WhoWill 00 28 06: GiveTreasureChest 64 0A 00 00 00 00 00 00 00 07: TakeOrGive 00 00 14 F5 The game engine stores the results of certain commands in memory. The exact handling of the parameters for each of the above lines is available on each command's individual page, however a brief overview of this event is: * 0. If map flag F5 is set, go to line 2. ** 1. Otherwise, go to line 5. * 2. Show the "Nothing here." message. * 3. Wait for the user to press a key. * 4. Stop execution of the script. * 5. Ask the user "Who will search?". If the user presses escape, the event will exit, otherwise execution will continue to the next line when they select a character. * 6. Use the GiveTreasureChest function to give the party a random amount of up to 10 gold. * 7. Set map flag F5, so that the user can't search this tree again. (See line 1) * There are no more lines, so the event is finished. As you can see, many commands (such as If) are capable of serving multiple purposes, and can do many different things depending on the parameters passed. All Opcodes Category:Engine